//
//  MSTestObject+C1.m
//  TestPrj
//
//  Created by 朱铅峰 on 2021/3/22.
//  Copyright © 2021 Xing. All rights reserved.
//

#import "MSTestObject+C1.h"
#import <objc/runtime.h>

@implementation MSTestObject (C1)

+ (void)load {
    
    Method superMethod0 = class_getInstanceMethod(self, @selector(originMethod0));
    Method categoryMethod0 = class_getInstanceMethod(self, @selector(swizzling0));
    method_exchangeImplementations(superMethod0, categoryMethod0);
    
    //重复Method swizzling同一个方法，同名,
    //刚好两次替换回原来的方法，等于没有hook
    Method superMethod = class_getInstanceMethod(self, @selector(originMethod1));
    Method categoryMethod = class_getInstanceMethod(self, @selector(swizzling1));
    method_exchangeImplementations(superMethod, categoryMethod);
    
    //重复Method swizzling同一个方法，不同名，
    //两个Category中，如swizzling自定义方法名不同，则自定义的方法都会被调用，调用顺序Compile Sources中在后边的先调用。
    Method s2 = class_getInstanceMethod(self, @selector(originMethod2));
    Method c3 = class_getInstanceMethod(self, @selector(swizzling2));
    method_exchangeImplementations(s2, c3);
}

- (void)swizzling0 {
    [self swizzling0];
    NSLog(@"%s",__FUNCTION__);
}

- (void)swizzling1 {
    [self swizzling1];
    NSLog(@"%s",__FUNCTION__);
}

- (void)swizzling2 {
    [self swizzling2];
    NSLog(@"%s",__FUNCTION__);
}

@end
